package cn.xuewei.controller;


import cn.xuewei.mapper.UserCourseMapper;
import cn.xuewei.pojo.dto.UserCourseDTO;
import cn.xuewei.pojo.entity.UserCourse;
import cn.xuewei.pojo.vo.CourseContentVO;
import cn.xuewei.response.ResultVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/v1/usercourses/")
public class UserCourseController {
    @Autowired
    private UserCourseMapper userCourseMapper;
    @RequestMapping("/{user_id}/{bvid}")
    public ResultVO select(@PathVariable Long user_id,@PathVariable String bvid){

        return ResultVO.ok(userCourseMapper.exists(user_id,bvid));
    }
    @RequestMapping("/insert")
    public ResultVO insert(@RequestBody UserCourseDTO userCourseDTO){
        UserCourse userCourse = new UserCourse();
        BeanUtils.copyProperties(userCourseDTO, userCourse);

        userCourse.setTime(new Date());
        userCourseMapper.insert(userCourse);
        return ResultVO.ok();
    }
    @RequestMapping("/mycourse/{user_id}")
    public ResultVO myCourse(@PathVariable Long user_id){
        List<CourseContentVO> list = userCourseMapper.selectByUserId(user_id);
        return ResultVO.ok(list);
    }



}
